

package tnviet.proj.jna.utilities;

import java.net.URL;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
/**
 *
 * @author Administrator
 */
public class ResourceManager {

    private static final Logger logger = Logger.getLogger(ResourceManager.class.getName());

    private final Class jNetAnalyzerClass;

    private ResourceBundle bundle = null;

    public ResourceManager(Class jNetAnalyzerClass) {
        this.jNetAnalyzerClass = jNetAnalyzerClass;

        String bundleName = jNetAnalyzerClass.getPackage().getName() + ".resources." + jNetAnalyzerClass.getSimpleName();

        try {
            bundle = ResourceBundle.getBundle(bundleName);
        } catch (MissingResourceException e) {
            logger.log(Level.SEVERE, "Couldn't load bundle: " + bundleName);
        }
    }
    public ResourceManager(Class jNetAnalyzerClass, Locale locale) {
        this.jNetAnalyzerClass = jNetAnalyzerClass;

        String bundleName = jNetAnalyzerClass.getPackage().getName() + ".resources." + jNetAnalyzerClass.getSimpleName();

        try {
            bundle = ResourceBundle.getBundle(bundleName, locale);
        } catch (MissingResourceException e) {
            logger.log(Level.SEVERE, "Couldn't load bundle: " + bundleName);
        }
    }
    public String getString(String key) {
        return bundle != null ? bundle.getString(key) : key;
    }
    public char getMnemonic(String key) {
        return (getString(key)).charAt(0);
    }
    public ImageIcon createImageIcon(String filename, String description) {
        String path = "resources/images/" + filename;

        URL imageURL = jNetAnalyzerClass.getResource(path);

        if (imageURL == null) {
            logger.log(Level.SEVERE, "unable to access image file: " + path);

            return null;
        } else {
            return new ImageIcon(imageURL, description);
        }
    }



}
